//
//  ViewController.m
//  UIApplication
//
//  Created by 移云 on 2019/11/20.
//  Copyright © 2019 MaoYeYeDeJiangCuCha. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property(nonatomic,assign)BOOL isSelect;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *changeBtn = [[UIButton alloc]initWithFrame:CGRectMake(UIScreen.mainScreen.bounds.size.width * 0.5 - 60, UIScreen.mainScreen.bounds.size.height * 0.5 + 20, 120, 40)];
    [changeBtn setTitle:@"红点提示" forState:UIControlStateNormal];
    [changeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [changeBtn addTarget:self action:@selector(redDotReminder) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:changeBtn];
    
    UIButton *changeBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(UIScreen.mainScreen.bounds.size.width * 0.5 - 60, UIScreen.mainScreen.bounds.size.height * 0.5 - 20, 120, 40)];
    [changeBtn2 setTitle:@"隐藏转态栏" forState:UIControlStateNormal];
    [changeBtn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [changeBtn2 addTarget:self action:@selector(hiddenStatusBar) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:changeBtn2];
    
    UIButton *changeBtn3 = [[UIButton alloc]initWithFrame:CGRectMake(UIScreen.mainScreen.bounds.size.width * 0.5 - 60, UIScreen.mainScreen.bounds.size.height * 0.5 - 60, 120, 40)];
    [changeBtn3 setTitle:@"网络指示器" forState:UIControlStateNormal];
    [changeBtn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [changeBtn3 addTarget:self action:@selector(networkActivity) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:changeBtn3];
    
    //打印出应用的沙盒目录
//    NSLog(@"%@",NSHomeDirectory());
    
//    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
//
//    NSString *filePath = [docPath stringByAppendingPathComponent:@"test.plist"];
//
//    NSArray *arr = @[@"猫爷爷",@"嘟嘟",@"popopi"];
//    [arr writeToFile:filePath atomically:YES];
//
//    NSLog(@"%@",filePath);
    
    
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [docPath stringByAppendingPathComponent:@"test.plist"];
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
    NSLog(@"%@",arr);
    
    
}

#pragma mark - 应用红点提示
-(void)redDotReminder{
    self.isSelect = !self.isSelect;
    //关于application的设置
    UIApplication *app = [UIApplication sharedApplication];
    
    //1.应用红点提示
    // set to 0 to hide. default is 0. In iOS 8.0 and later, your application must register for user notifications using -[UIApplication registerUserNotificationSettings:] before being able to set the icon badge.
    
    UIUserNotificationCategory *category = [[UIUserNotificationCategory alloc]init];
    
    NSSet *set = [NSSet setWithObject:category];
    
    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:set];
    
    [app registerUserNotificationSettings:setting];
    
    
    if (self.isSelect){
        app.applicationIconBadgeNumber = 5;
    }else{
       app.applicationIconBadgeNumber = 0;
    }
}

#pragma mark - 隐藏转态栏
//代码实现控制
//在info.plist 添加View controller-based status bar appearance （在最下面）
-(void)hiddenStatusBar{
    self.isSelect = !self.isSelect;
    //关于application的设置
    UIApplication *app = [UIApplication sharedApplication];
    if (self.isSelect){
        app.statusBarHidden = YES;
    }else{
        app.statusBarHidden = NO;
    }
}


#pragma mark - 网络指示器
-(void)networkActivity{
    self.isSelect = !self.isSelect;
    //关于application的设置
    UIApplication *app = [UIApplication sharedApplication];
    if (self.isSelect){
        app.networkActivityIndicatorVisible = YES;
    }else{
        app.networkActivityIndicatorVisible = NO;
    }
    
}

#pragma mark - openURL: 打电话/发短信/邮件/跳转到其他应用里面




@end
